<template>
	<view class="outBox">
		<u-navbar leftText="人员绑定" leftIconColor="#fff" :autoBack="true" bgColor="rgba(0, 0, 0, 0.6)">
			<view class="left-slot" slot="left">
				<u-icon name="arrow-left" color="#fff"></u-icon>
				<text>{{ '人员绑定' }}</text>
			</view>
		</u-navbar>
		<VideoBox>
			<template #content>
				<view class="content" @click.stop="closeInfoBox">
					<view class="bindingBox">
						<view class="user">
							<view class="img">
								<text v-if="!managerInfo.customerManagerName">暂未绑定</text>
								<image v-else :src="managerInfo.customerManagerAvatar" mode="scaleToFill"></image>
							</view>
							<view class="name">
								{{ managerInfo.customerManagerName || '' }}
							</view>
						</view>
						<view class="btns">
							<view class="btnOut" v-if="managerInfo.isWaitExamine">
								<view class="btn">
									绑定中，待审核
								</view>
							</view>
							<view class="btnOut" v-else-if="managerInfo.customerManagerName">
								<view class="btn" @click="handleUnBanding">
									解绑我的哥哥
								</view>
							</view>
							<view class="btnOut" v-else>
								<view class="btn" @click="getnav('/pages/manager/list')">
									绑定我的哥哥
								</view>
							</view>
						</view>
						<view class="btns">
							<view class="btnOut btnOut3">
								<view class="btn btn3" @click="getnav('/pages/distribution/system')">
									<text class="myText">我的社区</text>
								</view>
							</view>
						</view>

						<view class="bindList">
							<view class="title">
								<view class="showInfoBox" :style="{
          background:`url(${baseImgUrl}manager/bg1.png)`,
          backgroundSize:'100% 100%',
		  display: showInfoBox ? 'block' : 'none'
				}">
									<view class="tit">
										<text>绑定说明：</text>
									</view>
									<view class="text">
										<text>
											哥哥享受弟弟带来的多重收益
										</text>
									</view>
									<view class="text">
										<view class="one">
											<text style="padding-right: 10rpx;">*</text>
											<text>分佣：详情见收入明细-分佣。</text>
										</view>
										<view class="one">
											<text style="padding-right: 10rpx;">*</text>
											<text>人数加成：详情见收入明细-人数加成。</text>
										</view>
										<view class="one">
											<text style="padding-right: 10rpx;">*</text>
											<text>成立社区：详见我的社区-成立社区。</text>
										</view>
									</view>
								</view>
								<text>已绑定我的弟弟</text>
								<image @click.stop="handleShowInfoBox" :src="`/static/reservation/img2.png`"
									mode="widthFix">
								</image>
								<view class="waitExamineBox" v-if="managerInfo.waitExamineNum > 0"
									@click="getnav('/pages/manager/waitExamineList')">
									<view class="circle ">{{managerInfo.waitExamineNum}}</view>
									<text>待审核的弟弟</text>
								</view>
							</view>

							<view class="items" v-for="item in managerInfo.bindCustomerList">
								<view class="item" :style="{
            backgroundImage: `url(${itemBg})`,
            backgroundSize: '100% 100%'
          }" @click="handleDetails(item)">
									<image :src="item.avatar" mode="scaleToFill"></image>
									<text class="name">{{ item.name }}</text>
									<text class="phone">{{ item.mobile }}</text>
								</view>
							</view>
						</view>
					</view>
					<!-- 	<u-modal :show="showDia" :title="'是否解绑'" @cancel="showDia = false" @confirm="comfirmUnBinding"
        :showCancelButton="true" :content='content'></u-modal> -->
					<diaBox ref="diaBoxRef" title="解绑哥哥" @comfireFunc="comfirmUnBinding" :content="'是否确认解绑？'"
						:show-btns="true">

					</diaBox>
					<diaBox ref="diaBoxRef2" title="弟弟详情" @comfireFunc="comfirmCheck" :show-btns="true"
						:show-cancel="false">
						<template v-slot:dia-cont>
							<view class="bindingBox">
								<view class="user">
									<view class="img">
										<image :src="infoDetails.avatar" mode="scaleToFill"></image>
									</view>
									<view class="dis-flex">
										<view class="name">
											{{ infoDetails.customerName }}
										</view>
									</view>
								</view>
							</view>
							<view class="selectTime">
								<text>选择日期：</text>
								<view class="timeBox">
									<ep-select v-model="selectTime" :options="monthList"
										@change="changeTime"></ep-select>
								</view>
							</view>

							<view class="items1">
								<view class="item1">
									<view class="label">
										<text>业绩总金额</text>
									</view>
									<view class="value">
										<text>{{ infoDetails.performance }}</text>
									</view>
								</view>
								<view class="item1">
									<view class="label">
										<text>发起拼卡门票总金额</text>
									</view>
									<view class="value">
										<text>{{ infoDetails.invitationNum }}</text>
									</view>
								</view>
								<view class="item1">
									<view class="label">
										<text>发起拼卡总数量</text>
									</view>
									<view class="value">
										<text>{{ infoDetails.ticketNum }}</text>
									</view>
								</view>
								<view class="item1">
									<view class="label">
										<text>组局总数量</text>
									</view>
									<view class="value">
										<text>{{ infoDetails.setsNum }}</text>
									</view>
								</view>
								<view class="item1">
									<view class="label">
										<text>VIP组局总数量</text>
									</view>
									<view class="value">
										<text>{{ infoDetails.vipSetsNum }}</text>
									</view>
								</view>

								<view class="item1">
									<view class="label">
										<text>邀约总数量</text>
									</view>
									<view class="value">
										<text>{{ infoDetails.invitationNum }}</text>
									</view>
								</view>
							</view>
						</template>
					</diaBox>
				</view>
			</template>
		</VideoBox>
	</view>
</template>

<script>
	import {
		getWXStatusHeight
	} from '@/utils/index.js'

	import itemBg from "@/static/order/itemBg.png"

	import {
		infoAndBorderList,
		saleCenterInfo,
		unBindCustomerApi,
		customerMonthListApi
	} from '../../api/api'

	import diaBox from "@/components/diaBox/index.vue"
	import VideoBox from "@/components/VideoBox/index.vue";

	export default {
		components: {
			VideoBox,
			diaBox
		},
		data() {
			return {
				baseImgUrl2: this.$baseImgUrl2,
				baseImgUrl: this.$baseImgUrl,
				videoUrl: this.$videoUrl,
				// 胶囊的宽度
				barWidth: 0,
				menuHeight: 0,
				managerInfo: {},
				showDia: false, // 绑定弹窗
				content: '确认是否解除绑定',
				itemBg: itemBg,
				showInfoBox: false,
				showInfoBox1: false,
				videoPath: "",
				infoDetails: {},
				monthList: [],
				selectTime: "",
				choiceItem: "",
			}
		},
		onLoad() {
			let obj = getWXStatusHeight()
			this.barWidth = obj.barWidth + 3
			this.menuHeight = obj.menuHeight

			// 生成最近6个月的月份列表
			// this.monthList = this.getRecentMonths().map(item => {
			//   return {
			//     label:item,
			//     value:item
			//   }
			// })
			// console.log( this.monthList," this.monthList")
		},
		onShow() {
			this.getManagerInfo()
			this.getVideoFile()
		},
		methods: {
			async getMonthList(id) {
				const res = await customerMonthListApi(id)
				if (res.code == 200) {
					this.monthList = res.data.map(item => {
						return {
							value: item,
							label: item
						}
					})
				}
			},
			changeTime(e) {
				this.selectTime = e
				this.handleDetails()
			},
			getRecentMonths(count = 6) {
				const months = [];
				const today = new Date();
				let year = today.getFullYear();
				let month = today.getMonth();

				for (let i = 0; i < count; i++) {
					let yearStr = year.toString();
					let monthStr = (month + 1).toString().padStart(2, '0'); // 月份从0开始计数，所以加1
					months.push(`${yearStr}-${monthStr}`);

					// 减少月份，如果月份小于0，则减少年份并重置月份为11（即12月）
					if (month > 0) {
						month--;
					} else {
						year--;
						month = 11;
					}
				}

				return months; // 最新的月份排在最后，所以反转数组
			},

			// 关闭弟弟详情
			comfirmCheck() {
				this.$refs.diaBoxRef2.show = false
			},
			// 查看详情
			async handleDetails(item) {
				console.log(item, "item");
				if (!item) {
					item = this.choiceItem
				} else {
					this.choiceItem = item
				}
				this.$refs.diaBoxRef2.show = true
				this.getMonthList(item.customerId)
				const res = await infoAndBorderList(item.customerId, this.selectTime)
				if (res.code == 200) {
					this.infoDetails = res.data
				}
				console.log(res, "res")
			},
			handleShowInfoBox() {
				this.showInfoBox = true
			},
			closeInfoBox() {
				this.showInfoBox = false
				this.showInfoBox1 = false
			},

			// 取消
			handleCansel() {
				this.$refs.diaBoxRef.show = false
			},
			// 解绑客户经理
			handleUnBanding() {
				this.showDia = true
				this.$refs.diaBoxRef.show = true
			},
			// 确认解绑
			async comfirmUnBinding() {
				const res = await unBindCustomerApi()
				if (res.code == 200) {
					uni.$u.toast(res.msg);
					await this.getManagerInfo()
					this.$refs.diaBoxRef.close()
				}
			},
			// 查询客户经理
			async getManagerInfo() {
				const res = await saleCenterInfo()
				console.log(res, "res");
				if (res.code == 200) {
					this.managerInfo = res.data
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.selectTime {
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 22rpx;

		.timeBox {
			width: 200rpx;
		}

		text {
			color: #fff;
		}

	}

	.items1 {
		background: rgba(0, 0, 0, 0.52);
		border-radius: 60rpx;
		border: 2rpx solid;
		padding: 48rpx;
		border: 2rpx solid #21253B;
		margin-top: 30rpx;
		backdrop-filter: blur(7px);

		.item1 {
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 62rpx;

			.label {
				font-weight: 500;
				font-size: 28rpx;
				color: #86909C;
				line-height: 28rpx;
				text-align: left;
				font-style: normal;
			}

			.value {
				font-weight: 500;
				font-size: 28rpx;
				color: #FFFFFF;
				line-height: 28rpx;
				text-align: right;
				font-style: normal;
			}
		}
	}

	.bindingBox {
		border-radius: 40rpx;
		padding: 40rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		position: relative;

		.user {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.img {
				width: 240rpx;
				height: 240rpx;
				border-radius: 106rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.name {
				text-align: center;
				font-weight: 600;
				font-size: 40rpx;
				color: #FFFFFF;
				line-height: 40rpx;
				text-align: center;
				font-style: normal;
			}

			image {
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}

	}

	.showInfoBox {
		width: 582rpx;
		box-sizing: border-box;
		padding: 68rpx 50rpx 45rpx;
		position: absolute;
		z-index: 5;
		top: 80%;
		left: 0rpx;
		font-size: 28rpx !important;
		font-weight: 400 !important;

		.tit {
			margin-bottom: 30rpx;
			color: #0FC6C2;
			line-height: 28rpx;
			text-align: left;
			font-style: normal;
		}

		.text {
			font-weight: 400;
			color: #FFFFFF;
			line-height: 44rpx;
			text-align: justify;
			font-style: normal;
			margin-bottom: 32rpx;
			display: flex;
			flex-direction: column;

			&:last-child {
				margin-bottom: 0;
			}

			.one {
				margin-bottom: 20rpx;

				&:last-child {
					margin-bottom: 0;
				}
			}
		}

		image {
			width: 32rpx;
		}
	}

	.showInfoBox1 {
		transform: translateY(112rpx) translateX(-86rpx);
	}


	.diaBox {
		margin-top: 40rpx;

		.text {
			margin-bottom: 20rpx;
			text-align: center;
			font-weight: 600;
			font-size: 28rpx;
			color: #FFFFFF;
			line-height: 32rpx;
			font-style: normal;
		}

		.btns {
			display: flex;
			justify-content: center;
			margin-top: 40rpx;

			.btn {
				width: 150rpx;
				line-height: 60rpx;
				font-size: 26rpx;
				text-align: center;
				color: #fff;
				background: linear-gradient(267deg, #CC34B3 0%, #541A66 100%);
				border-radius: 100rpx 100rpx 100rpx 100rpx;
				position: relative;

				&:nth-child(1) {
					margin-right: 20rpx;
				}
			}
		}
	}

	video {
		width: 100%;
		height: 100%;
		object-fit: cover;
		/* 确保视频填充整个容器，可能会裁剪视频 */
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 0;
	}

	.bindList {
		background: rgba(0, 0, 0, 0.52);
		border-radius: 60rpx;
		border: 2rpx solid;
		padding: 48rpx;
		border: 2rpx solid #21253B;
		margin-top: 30rpx;
		min-height: 200rpx;
		width: 684rpx;

		.waitExamineBox {
			position: absolute;
			right: 0;
			width: 164rpx;
			height: 40rpx;
			background: linear-gradient(162deg, rgba(15, 198, 194, 0.44) 0%, rgba(133, 243, 241, 0.69) 100%);
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			text {
				font-size: 20rpx;
				color: #FFFFFF;
				line-height: 24rpx;
			}

			.circle {
				position: absolute;
				right: -9rpx;
				top: -9rpx;
				background-color: #fff;
				border-radius: 50%;
				color: #86909C;
				width: 18rpx;
				height: 18rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 18rpx;
			}
		}

		.items {
			.item {
				margin-top: 30rpx;
				width: 588rpx;
				height: 140rpx;
				background-size: 100% 100%;
				display: flex;
				align-items: center;

				image {
					width: 84rpx;
					height: 84rpx;
					border-radius: 50%;
					margin-right: 20rpx;
					margin-left: 30rpx;
				}

				.name {
					font-weight: 500;
					font-size: 28rpx;
					color: #FFFFFF;
					line-height: 28rpx;
					text-align: left;
					font-style: normal;
				}

				.phone {
					font-weight: 500;
					font-size: 28rpx;
					color: #86909C;
					line-height: 28rpx;
					text-align: left;
					font-style: normal;
				}

				text {
					margin-left: 30rpx;
				}
			}
		}

		.title {
			position: relative;
			font-weight: 400;
			height: 60rpx;
			font-size: 28rpx;
			color: #86909C;
			line-height: 28rpx;
			text-align: left;
			font-style: normal;
			padding-bottom: 20rpx;
			display: flex;
			align-items: center;
			position: relative;

			image {
				width: 32rpx;
				margin-left: 16rpx;
			}
		}
	}

	.bindingBox {
		//background-color: rgba(20, 20, 33, 0.9);
		border-radius: 40rpx;
		padding: 40rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		//border: 2rpx solid #21253B;

		.btns {
			margin-top: 46rpx;

			.btnOut {
				border-radius: 64rpx;
				box-shadow: 0rpx 0rpx 40rpx 38rpx rgba(15, 198, 194, 0.25);
			}


			.btn {
				font-size: 32rpx;
				text-align: center;
				color: #fff;
				width: 400rpx;
				height: 110rpx;
				line-height: 110rpx;
				background: #0FC6C2;
				border-radius: 64rpx;
				box-shadow: inset 0rpx 14rpx 34rpx 0rpx #FFFFFF;
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;

				.iconImg {
					width: 32rpx;
					margin-left: 8rpx;
				}

				.myText {
					text {
						font-weight: 600;
						font-size: 36rpx;
						color: #FFFFFF;
						line-height: 36rpx;
						text-align: left;
						font-style: normal;
					}
				}
			}

			.btnOut3 {
				border-radius: 64rpx;
				box-shadow: 0rpx 0rpx 40rpx 38rpx rgba(71, 136, 247, 0.25);
			}

			.btn3 {
				background: #4788f7;
			}

			.btn4 {
				background: #f97609;
			}

			.btnOut4 {
				border-radius: 64rpx;
				box-shadow: 0rpx 0rpx 40rpx 38rpx rgba(249, 118, 9, 0.25);
			}

		}

		.user {
			.img {
				width: 240rpx;
				height: 240rpx;
				border-radius: 106rpx;
				border: 3rpx solid #293032;
				background-color: #0e1113;
				overflow: hidden;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			text {
				font-weight: 400;
				font-size: 36rpx;
				color: #86909C;
				line-height: 36rpx;
			}

			image {
				width: 100%;
				height: 100%;
			}

			.name {
				text-align: center;
				margin-top: 20rpx;
				font-size: 40rpx;
				font-weight: bolder;
				color: #fff;
			}
		}

	}

	.content {
		position: relative;
		padding: 20rpx 40rpx;
		box-sizing: border-box;
		position: relative;
		z-index: 9;
	}

	.left-slot {
		color: #fff;
		display: flex;
		align-items: center;

		text {
			margin-left: 16rpx;
		}

		image {
			width: 40rpx;
			margin-right: 30rpx;
		}
	}

	.outBox {}

	.bg {
		background: rgba(0, 0, 0, 0.6);
		position: fixed;
		height: 100vh;
		width: 100vw;
		z-index: 2;
	}
</style>